DEW.BaseLayoutController = function() {};

$.extend(DEW.BaseLayoutController.prototype, {
    render: function() {
//        DEW.ViewManager.removeAll();
        this.displayLayout();
        this.displayHeader();
        this.displayBody();
        this.displayFooter();
    },

    displayLayout: function() {
        var baseLayout = new DEW.BaseLayout();
        baseLayout.render();
        $(baseLayout.el).appendTo("#content");
//        DEW.ViewManager.addView(baseLayout);
    },

    displayHeader: function() {
        var header = new DEW.Header();
        header.render();
        $(header.el).appendTo("#header");
    },

    displayBody: function() {
        
        //Cargando categorias
        var categoriesCollection = new DEW.CategoriesCollection();
        categoriesCollection.fetch({reset: true});

        var sidebar = new DEW.Sidebar({
            model: categoriesCollection
        });

        sidebar.on("changeCategory",function(categoryId) {
            listView.categoryId = categoryId;
            listView.render();
        });

        $(sidebar.el).appendTo(".sidebar");
//        DEW.ViewManager.addView(header);

        //Cargando lista de datos
        var listCollection = new DEW.ListCollection();
        listCollection.fetch({reset:true});
//var listCollection = DEW.StoreManager.get('listCollection');
//        if (listCollection === null) {
//            listCollection = new DEW.ListCollection();
//            listCollection.fetch({reset:true});
//            
//        }

        //Creando la vista y asociandole el modelo
        var listView = new DEW.List({
            model: listCollection
        });
        $(listView.el).appendTo(".page-content");
//        DEW.ViewManager.addView(listView);
        
 },

        //var sidebar = new DEW.Sidebar();
        //sidebar.render();
        //$(sidebar.el).appendTo(".sidebar");

        //var list = new DEW.List();
        //list.render();
        //$(list.el).appendTo(".page-content");
    //},

    displayFooter: function() {
        var footer = new DEW.Footer();
        footer.render();
        $(footer.el).appendTo("#footer");
//        DEW.ViewManager.addView(footer);
        
    }

});